package pers.lance.jmsproject.server;

import com.fasterxml.jackson.databind.ObjectMapper;
import pers.lance.jmsproject.dao.UserDao;
import pers.lance.jmsproject.dao.UserDaoImp;
import pers.lance.jmsproject.pojo.User;

import java.io.IOException;

public class DataService {
    JmsServer jmsServer = new JmsServer("tcp://localhost:61616","lance.queue");
    UserDao userDao = new UserDaoImp();
    ObjectMapper objectMapper = new ObjectMapper();

    public void service(){
        String msg =  jmsServer.getMessage();
        System.out.println("receive msg = " + msg);
        try {
            User user = objectMapper.readValue("msg", User.class);
            userDao.addUser(user);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
